﻿// https://github.com/NRatel/NRFramework.UI

using UnityEngine;

namespace NRFramework
{
    public abstract class UIWidget : UIView
    {
        protected UIView parentView;
        protected string widgetId => viewId;
        public UIWidgetBehaviour widgetBehaviour { get { return (UIWidgetBehaviour)viewBehaviour; } }

        protected internal void Create(string widgetId, UIView parentView, Transform parentTransform, string prefabPath)
        {
            this.parentView = parentView;
            base.CreateByResLoader(widgetId, parentTransform, prefabPath);
        }

        protected internal void Create(string widgetId, UIView parentView, Transform parentTransform, UIWidgetBehaviour widgetBehaviour)
        {
            this.parentView = parentView;
            base.CreateSoftly(widgetId, parentTransform, widgetBehaviour);
        }

        protected void RemoveSelf()
        {
            parentView.RemoveWidget(widgetId);
        }

        protected override void OnInternalRemoving()
        {
            parentView = null;

            base.OnInternalRemoving();
        }
    }
}
